package edu.nf.waimai.dao.shop.impl;

import edu.nf.util.DBUtils;
import edu.nf.waimai.dao.shop.ShopTypeDAO;
import edu.nf.waimai.model.shop.ShopType;
import org.nf.db.util.SqlExecutor;
import org.nf.db.util.result.BeanListHandler;

import java.util.List;

public class ShopTypeDAOImpl implements ShopTypeDAO {

    /**
     * 查询全部商家信息
     * @return
     */
    @Override
    public List<ShopType> listShopType() {
        SqlExecutor sqlExecutor = new SqlExecutor(DBUtils.getConnection());
        BeanListHandler<ShopType> listHandler = new BeanListHandler<>(ShopType.class);
        String sql = "SELECT shop_type_id,shop_type_name FROM shop_type";
        return sqlExecutor.executeQuery("",listHandler);
    }

    /**
     * 添加商家类型
     * @param shopType
     * @return
     */
    @Override
    public int addShopType(ShopType shopType) {
        SqlExecutor sqlExecutor = new SqlExecutor(DBUtils.getConnection());

        String sql = "insert into shop_type(shop_type_name) values(?)";

        return sqlExecutor.executeUpdate(sql,shopType.getShopTypeName());
    }

    /**
     * 删除商家类型
     * @param shopTypeId
     * @return
     */
    @Override
    public int delShopType(int shopTypeId) {
        SqlExecutor sqlExecutor = new SqlExecutor(DBUtils.getConnection());

        String sql = "delete from shop_type where shop_type_id = ?";

        return sqlExecutor.executeUpdate(sql,shopTypeId);
    }


}
